package com.mkyong.stock;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;

@Embeddable
public class StockCategoryId implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private StockJoinTable stock;
	private CategoryJoinTable category;
	
	@ManyToOne
	public StockJoinTable getStock() {
		return stock;
	
	}
	
	public void setStock(StockJoinTable stock) {
		this.stock = stock;
	}
	
	@ManyToOne
	public CategoryJoinTable getCategory() {
		return category;
	}
	
	public void setCategory(CategoryJoinTable category) {
		this.category = category;
	}
	
	public boolean equals(Object o) {
		
		if(this == o)
		{
			return true;
		}
		
		if(o == null || getClass() != o.getClass())
		{
			return false;
		}
		
		StockCategoryId that = (StockCategoryId) o;
		
		if(stock != null ? !stock.equals(that.stock) : that.stock != null)
		{
			return false;
		}
		
		if(category != null ? !category.equals(that.category) : that.category != null)
		{
			return false;
		}
		
		return true;
		
	}
	
	public int hashCode()
	{
		int result;
		
		result = (stock != null ? stock.hashCode() : 0);
		result = 31 * result + (category != null ? category.hashCode() : 0);
		
		return result;
	}

}
